﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace WebOS.Core.Log
{
    /// <summary>
    /// BOTWAVE操作日志类

    /// </summary>
    public class OperationLog
    {
        #region Properties
        /// <summary>
        /// 操作开始时间
        /// </summary>
        private DateTime opStartTime;
        public DateTime OpStartTime { get { return this.opStartTime; } set { this.opStartTime = value; } }
        /// <summary>
        /// 用户标识（用户名）
        /// </summary>
        private string portalID;
        public string PortalID { get { return this.portalID; } set { this.portalID = value; } }
        /// <summary>
        /// 客户端IP地址
        /// </summary>
        private string clientIP;
        public string ClientIP { get { return this.clientIP; } set { this.clientIP = value; } }
        /// <summary>
        /// 客户端计算机名称
        /// </summary>
        private string clientComputerName;
        public string ClientComputerName { get { return this.clientComputerName; } set { this.clientComputerName = value; } }
        /// <summary>
        /// 服务器IP地址
        /// </summary>
        private string serverIP;
        public string ServerIP { get { return this.serverIP; } set { this.serverIP = value; } }
        /// <summary>
        /// 操作结束时间
        /// </summary>
        private DateTime opEndTime;
        public DateTime OpEndTime { get { return this.opEndTime; } set { this.opEndTime = value; } }
        /// <summary>
        /// 操作类型名称
        /// </summary>
        private string operationName;
        public string OperationName { get { return this.operationName; } set { this.operationName = value; } }
        /// <summary>
        /// 操作类型编号
        /// </summary>
        private string operationID;
        public string OperationID { get { return LogData.GetOperationId(this.operationName); } }
        /// <summary>
        /// 异常类型名称
        /// </summary>
        private string exceptionName;
        public string ExceptionName { get { return this.exceptionName; } set { this.exceptionName = value; } }
        /// <summary>
        /// 异常类型编号
        /// </summary>
        private string exceptionID;
        public string ExceptionID { get { return LogData.GetExceptionId(this.exceptionName); } }
        /// <summary>
        /// 描述信息
        /// </summary>
        private string description;
        public string Description { get { return this.description; } set { this.description = value; } }
        #endregion

        #region Constructors
        /// <summary>
        /// 构造函数
        /// </summary>
        public OperationLog()
        {
            this.PortalID = System.Web.HttpContext.Current.User.Identity.Name;
            this.ClientIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            this.ClientComputerName = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_HOST"];
            this.ServerIP = System.Web.HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"];

            this.OpStartTime = DateTime.Now;
            this.OpEndTime = DateTime.Now;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="portalId">用户标识（用户名）</param>
        /// <param name="operationName">操作类型名称</param>
        /// <param name="exceptionName">异常类型名称</param>
        /// <param name="description">描述信息</param>
        public OperationLog(string portalId, string operationName, string exceptionName, string description)
            : this()
        {
            this.PortalID = portalId;
            this.OperationName = operationName;
            this.ExceptionName = exceptionName;
            this.Description = description;
        }
        #endregion
    }
}
